
<template>
  <el-dialog
    v-model="conf.visible"
    title="修改 系统信息"
    width="30%"
    draggable
    :before-close="hide"
  >
<el-form :model="form" size="small" ref="form" :rules="rules">


 <!--系统名称 输入控件 -->
 <el-form-item prop="name" label="系统名称" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.name" maxlength="32"  placeholder="请输入系统名称" />
 </el-form-item>

 <!--版本 输入控件 -->
 <el-form-item prop="version" label="版本" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.version" maxlength="64"  placeholder="请输入版本" />
 </el-form-item>

 <!--首页地址 输入控件 -->
 <el-form-item prop="index_url" label="首页地址" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.index_url" maxlength="64"  placeholder="请输入首页地址" />
 </el-form-item>

  <!--超时时长 数字控件 -->
  <el-form-item prop="login_timeout" label="超时时长" label-width="100px" label-position="right">
    <el-input-number style="width: 100%" v-model="form.login_timeout"/>
  </el-form-item>

  

 <!--logo 输入控件 -->
 <el-form-item prop="logo" label="logo" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.logo" maxlength="128"  placeholder="请输入logo" />
 </el-form-item>

 <!--主题样式 输入控件 -->
 <el-form-item prop="theme" label="主题样式" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.theme" maxlength="128"  placeholder="请输入主题样式" />
 </el-form-item>

 <!--页面布局样式 输入控件 -->
 <el-form-item prop="layout" label="页面布局样式" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.layout" maxlength="128"  placeholder="请输入页面布局样式" />
 </el-form-item>

 <!--背景图片 输入控件 -->
 <el-form-item prop="bg_url" label="背景图片" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.bg_url" maxlength="32"  placeholder="请输入背景图片" />
 </el-form-item>

 <!--唯一标识 输入控件 -->
 <el-form-item prop="ident" label="唯一标识" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.ident" maxlength="32"  placeholder="请输入唯一标识" />
 </el-form-item>

 <!--登录地址 输入控件 -->
 <el-form-item prop="login_url" label="登录地址" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.login_url" maxlength="64"  placeholder="请输入登录地址" />
 </el-form-item>

  <!--状态 switch控件 -->
  <el-form-item prop="enable" label="状态" label-width="100px" label-position="right">
    <el-switch v-model="form.enable_switch" />
  </el-form-item>

  

</el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="hide">取消</el-button>
        <el-button type="primary" @click="save">提交</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      conf: {
        visible: false,
        uploadPath:this.$theia.env.join("/file/upload"),
      },
    rules:{
      name:[{
          required:true,
          message:"请输入系统名称",
          trigger: 'blur',
      }],
      version:[{
          required:true,
          message:"请输入版本",
          trigger: 'blur',
      }],
      index_url:[{
          required:false,
          message:"请输入首页地址",
          trigger: 'blur',
      }],
      login_timeout:[{
          required:true,
          message:"请输入超时时长",
          trigger: 'blur',
      }],
      logo:[{
          required:false,
          message:"请输入logo",
          trigger: 'blur',
      }],
      theme:[{
          required:false,
          message:"请输入主题样式",
          trigger: 'blur',
      }],
      layout:[{
          required:false,
          message:"请输入页面布局样式",
          trigger: 'blur',
      }],
      bg_url:[{
          required:false,
          message:"请输入背景图片",
          trigger: 'blur',
      }],
      ident:[{
          required:true,
          message:"请输入唯一标识",
          trigger: 'blur',
      }],
      login_url:[{
          required:false,
          message:"请输入登录地址",
          trigger: 'blur',
      }],
      enable:[{
          required:true,
          message:"请输入状态",
          trigger: 'blur',
      }],
    },
    form:{
        name:"",
        version:"",
        index_url:"",
        login_timeout:"",
        logo:"",
        theme:"",
        layout:"",
        bg_url:"",
        ident:"",
        login_url:"",
        enable_switch:false,
        },
      }},
  methods: {
    show(form) {
      this.conf.visible = true;
      this.get(form)
    },
      get(form){
        let that = this
        this.$theia.http.get("/systeminfo",form).then(res=>{
          res.enable_switch = res.enable == 0
        Object.assign(that.form, res)
        }).catch(res=>{
          let code = res.response.status
          let msg = `系统信息查询失败(${code})`
          that.$notify.error({title: '失败',message:msg ,duration:5000})
        })
    },
    save(){
       this.form.enable = this.form.enable_switch?0:1;
        this.$refs.form.validate((v=>{
            if(v){
                this.onSave()
               
            }
        }))
    },
    onSave(){
        let that = this
        this.$theia.http.put("/systeminfo",this.form).then(res=>{
            that.$notify.success({title: '成功',message: '系统信息保存成功',duration:5000})
            that.$emit("onsaved")
            that.hide()
        }).catch(res=>{
          let code = res.response.status
          let msg = `系统信息修改失败(${code})`
          that.$notify.error({title: '失败',message: msg,duration:5000})
        })
    },
    hide() {
      this.conf.visible = false;
      this.$refs.form.resetFields();
    },
     onUploadSuccess(response){
      
    },
  },
};
</script>

<style>
</style>